package com.custom.pullrecycleview;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class ListAdapter extends BaseAdapter {

    private Activity activity;
    private List<String> list;

    public ListAdapter(Activity activity, List<String> list) {
        this.activity = activity;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ListViewHolder listViewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(activity).inflate(R.layout.layout_listview_item, parent, false);
            listViewHolder = new ListViewHolder();
            listViewHolder.textview = convertView.findViewById(R.id.textview);
            convertView.setTag(listViewHolder);
        } else {
            listViewHolder = (ListViewHolder) convertView.getTag();
        }
        listViewHolder.textview.setText(list.get(position));
        return convertView;
    }

    class ListViewHolder {
        TextView textview;
    }

}
